<template>
  <div class="container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>全部安全事件</span>
          <el-button @click="router.back()">返回</el-button>
        </div>
      </template>
      <el-timeline>
        <el-timeline-item
          v-for="(event, index) in events"
          :key="index"
          :timestamp="event.time"
          placement="top"
        >
          <el-alert :title="event.description" :type="event.level" />
        </el-timeline-item>
      </el-timeline>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter()
interface SecurityEvent {
  time: string
  description: string
  level: string
}

const events = ref<SecurityEvent[]>([])

const fetchEvents = async () => {
  const res = await axios.get('http://127.0.0.1:5000/api/security-events?limit=100')
  events.value = res.data.data
}

onMounted(fetchEvents)
</script>
<style lang="css" scoped>
.container {
  padding: 20px;
  min-width: 1200px;
}
</style>
